<?php

namespace app\store\model;

use app\common\model\SurveyQuestion as SurveyQuestionModel;
use app\common\model\SurveyOption as SurveyOptionModel;

/**
 * 问卷问题模型
 * Class SurveyQuestion
 * @package app\store\model
 */
class SurveyQuestion extends SurveyQuestionModel
{
    protected $name = 'survey_question';
    
    /**
     * 获取问题列表
     * @param int $surveyId
     * @return array
     */
    public function getQuestionsBySurveyId($surveyId)
    {
        return $this->where('survey_id', $surveyId)
                    ->where('is_delete', 0)
                    ->order('sort', 'asc')
                    ->select()
                    ->toArray();
    }
    public function add($data)
    {
        $data['wxapp_id'] = self::$wxapp_id;
        // 插入记录
        return $this->allowField(true)->save($data);
    }
    /**
     * 定义问题和选项的一对多关联
     */
    public function options()
    {
        return $this->hasMany(SurveyOptionModel::class, 'question_id', 'id')->where("is_delete","0");
        // return $this->hasMany(SurveyOptionModel::class, 'question_id', 'id');
    }
    
}